package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.manor.ManorMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2021/6/8 15:29
 */
@Cmd(code = GameProtocol.S_MANOR_CROSS_VISIT_MANOR, desc = "跨服来拜访庄园")
public class CrossVisitManorCmd implements Command {
    private long originPlayerId;
    private long originServerId;
    private long visitPlayerId;

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ManorProto.CrossVisitOtherManorReqMsg msg = ManorProto.CrossVisitOtherManorReqMsg.parseFrom(packet.getBytes());
        originPlayerId = msg.getOriginPlayerId();
        originServerId = msg.getOriginServerId();
        visitPlayerId = msg.getVisitPlayerId();
        ManorProto.CrossVisitOtherManorRespMsg.Builder respMsg = ManorProto.CrossVisitOtherManorRespMsg.newBuilder();
        respMsg.setMsg(ManorMgr.getVisitMsg(visitPlayerId));
        respMsg.setOriginPlayerId(originPlayerId);
        respMsg.setOriginServerId(originServerId);
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_CROSS_VISIT_PLAYER_MANOR_RESP, respMsg);
        GamePlayerMgr.sendPacket(0,message);
    }
}
